package com.supermarket_project.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {

    private BeanCopyUtils(){}

    public static <V> V copyBean(Object resource,Class<V> clazz){
        V result = null;
        try {
            result = clazz.newInstance();
            BeanUtils.copyProperties(resource,result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static <O,V> List<V> copyBeanList(List<O> resouce,Class<V> clazz){
        List<V> result = resouce.stream()
                .map(o -> copyBean(o, clazz))
                .collect(Collectors.toList());
        return result;
    }
}

